const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    card_id: '',
    goods_list: [],
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  onLoad: function (options) {
    // wx.showToast({
    //   title: '开发中，请期待~',
    // })
    // setTimeout(function(){
    //   wx.navigateBack({

    //   })
    // },1500)

    var that = this;
    that.setData({
      card_id: options.id
    });
  },
  onShow: function (options) {
    wx.showLoading({
      title: '加载中……',
    })
    this.getCardGoodList();

  },
  getCardGoodList: function () {
    let that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/Card/shopCardGood/openid/' + app.globalData.openid + '/card_id/' + that.data.card_id, function (res) {
      that.setData({
        goods_list: res.data
      })
      wx.hideLoading();
    });
  },
  onReady: function () {

  },
  editGood: function (e) {
    const data = e.target.dataset;
    wx.navigateTo({
      url: 'addgood?type=' + data.type + '&id=' + data.id,
    })
  },

  delGood: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除该服务商品？',
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '删除中……',
          })
          app.ihttpGet('https://www.58zltc.com/api.php/Card/delGood/openid/' + app.globalData.openid + '/id/' + e.target.dataset.id, function (res) {
            wx.showModal({
              title: '提示',
              content: res.data.err_msg,
              showCancel: false,
              success: function () {
                if (res.data.err_code === 0) {
                  that.getCardGoodList();
                }
              }
            })
          });
        }
      }
    })
  }


})